<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>5、组合模式</title>
</head>

<body>
    <button id="super">超级遥控器</button>
    <script src="./../dist/5、组合模式/5、main.js"></script>
    <script>
        // 宏命令模式-->以工场模式实现
        function MacroCommand() {
            return {
                commandList: [],
                add(command) {
                    this.commandList.push(command);
                },
                execute() {
                    for (var i = 0; i < this.commandList.length; i++) {
                        this.commandList[i].execute();
                    }
                }
            }
        };

        // 测试用例
        var closeDoorCommand = {
            execute() {
                console.log('关门咯！');
            }
        };
        var openDoorCommand = {
            execute() {
                console.log('开门啦！');
            }
        };
        var macroInstance = new MacroCommand();
        macroInstance.add(closeDoorCommand);
        macroInstance.add(openDoorCommand);
        macroInstance.execute();// 两个命令都被成功调用

    </script>
</body>

</html>